package com.compty.paint.manager;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.compty.core.hibernate.HibernateEntityDao;
import com.compty.paint.domain.CityInfo;

public class CityInfoManager extends HibernateEntityDao<CityInfo>{
	
	private static List<CityInfo>  cityInfoList = null;
	private static Map<Long,List<CityInfo>> province_CityMap = new ConcurrentHashMap<Long,List<CityInfo>>(); 
	
	 public List<CityInfo> getAll() {
		 
		 if( cityInfoList == null){
			 List<CityInfo>  cityInfos =  super.getAll();
			 cityInfoList  = cityInfos;
		 }
		 
		 return cityInfoList;
	 }
	 
	 /**
	  *@Todo:由省份ID查找城市列表
	  *@author:朱庆辉
	  *@CreateTime:2012-4-16 下午03:35:25
	  * @param provinceId 省份ID
	  * @return
	  */
	 public List<CityInfo> findCityByProvinceId(Long provinceId) {
		 
		 if(provinceId == null) return null;
		 
		 if(province_CityMap.containsKey(provinceId)){
			 List<CityInfo> list = province_CityMap.get(provinceId);
			 return list;
		 }
		 else{
			 List<CityInfo> list = findBy("provinceInfo.id", provinceId);
			 province_CityMap.put(provinceId, list);
			 return list;
		 }
	 }

}
